package com.timoon.component.panel.editor;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.resource.CssResourceReference;

import com.googlecode.wicket.jquery.ui.Options;
import com.googlecode.wicket.jquery.ui.kendo.button.AjaxButton;
import com.googlecode.wicket.jquery.ui.kendo.editor.Editor;
import com.googlecode.wicket.jquery.ui.panel.JQueryFeedbackPanel;
import com.timoon.app.resource.css.CSSLocation;

/**
 *<p></p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013.4.1</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */
public class EditorPanel extends Panel {
	
	private boolean isBtnVisiable=true;

	public EditorPanel(String id,IModel model,boolean isBtnVisiable) {
		super(id);
		// TODO Auto-generated constructor stub
		
		this.isBtnVisiable=isBtnVisiable;
		
		Form<Void> form=new Form<Void>("wk_form");
		add(form);
		
		Options ops=new Options();
		ops.set("messages", "{bold:'加粗',fontNameInherit:'字体',fontSizeInherit:'大小'}");
		
		final Editor<String> editor=new Editor<>("wk_editor",model,ops);
		form.add(editor);
		
		form.add(new AjaxButton("wk_save") {
			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				// TODO Auto-generated method stub
				super.onSubmit(target, form);
				
				EditorPanel.this.onEditorSubmit(target);
			}
			
			@Override
			public boolean isVisible() {
				// TODO Auto-generated method stub
				return EditorPanel.this.isBtnVisiable;
			}
		});
	}
	
	@Override
	public void renderHead(IHeaderResponse response) {
		// TODO Auto-generated method stub
		super.renderHead(response);
		
		response.render(CssHeaderItem.forReference(new CssResourceReference(CSSLocation.class,"kendo.common.min.css")));
		response.render(CssHeaderItem.forReference(new CssResourceReference(CSSLocation.class,"kendo.default.min.css")));
	}
	
	protected void onEditorSubmit(AjaxRequestTarget target){};

}
